from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

# 初始化Chrome浏览器
driver = webdriver.Chrome()

# 打开百度首页
driver.get("https://www.baidu.com")
driver.maximize_window()

try:
    # 综合定位示例
    search_input = driver.find_element(By.ID, "kw")
    search_button = driver.find_element(By.ID, "su")

    # 输入搜索关键词并点击搜索
    search_input.send_keys("Selenium")
    search_button.click()

    print("搜索操作执行成功")

except Exception as e:
    print("综合元素定位失败：", e)

finally:
    sleep(5)  # 休眠5秒供截图
    driver.quit()